"use strict";
// 枚举（Enum）类型用于取值被限定在一定范围内的场景，比如一周只能有七天，颜色限定为红绿蓝等。
const res = () => 120;
var Days;
(function (Days) {
    Days[Days["one"] = 0] = "one";
    Days[Days["two"] = 1] = "two";
    Days[Days["three"] = 2] = "three";
    Days[Days["four"] = res()] = "four";
    Days[Days["five"] = 0] = "five";
})(Days || (Days = {}));
// 字符串枚举是不能使用计算所得项的  可以使用其它成员
const stringres = () => "zks";
var StringDa;
(function (StringDa) {
    StringDa["a"] = "dasdsa";
    // b=stringres()//报错
    StringDa[StringDa["b"] = StringDa.a.length] = "b";
})(StringDa || (StringDa = {}));
console.log(Days, 'days');
console.log(Days[1]);
console.log(Days["one"]);
console.log(StringDa, 'StringDa');
// 异构枚举
var Gender;
(function (Gender) {
    Gender[Gender["Male"] = 1] = "Male";
    Gender["Female"] = "\u5973";
})(Gender || (Gender = {}));
console.log(Gender["Male"]);
console.log(Gender["Female"]);
console.log(Gender[2]);
console.log(Gender[1]);
console.log(Gender["女"]);
// 默认第一个值得类型必须是数字型  如果是字符串类型那么枚举类型不会进行自增需要手动全部添加
var rgb;
(function (rgb) {
    //   r = "201",//报错
    rgb[rgb["r"] = 201] = "r";
    rgb[rgb["g"] = 202] = "g";
    rgb[rgb["b"] = 203] = "b";
})(rgb || (rgb = {}));
// 枚举项有两种类型：常数项（constant member）和计算所得项（computed member）。
// 前面我们所举的例子都是常数项
// 字面枚举 表达式（基本上是字符串字面或数字字面）
// 对先前定义的常量枚举成员的引用（可以源自不同的枚举）
// 带括号的常量枚举表达式
// 应用于常量枚举表达式的 +、-、~ 一元运算符之一
// +、-、*、/、%、<<、>>、>>>、&、|、^ 以常量枚举表达式作为操作数的二元运算符  也是常数项
// enum Color { Red, Green, Blue = "blue".length };
// 上面的例子中，"blue".length 就是一个计算所得项。
var Colors;
(function (Colors) {
    Colors[Colors["Red"] = 0] = "Red";
    Colors[Colors["Green"] = 1] = "Green";
    Colors[Colors["Blue"] = "blue".length] = "Blue";
    //   yellow, //报错 无法获得初始值  需要手动赋值
})(Colors || (Colors = {}));
console.log(0 /* obj.up */);
console.log(2 /* obj.sum */);
console.log(ABC.a);
console.log(0 /* abc.Up */);
var Operator;
(function (Operator) {
    Operator[Operator["ADD"] = 0] = "ADD";
    Operator[Operator["DIV"] = 1] = "DIV";
    Operator[Operator["MUL"] = 2] = "MUL";
    Operator[Operator["SUB"] = 3] = "SUB";
})(Operator || (Operator = {}));
function compute(op, a, b) {
    switch (op) {
        case Operator.ADD:
            return a + b;
        case Operator.DIV:
            return a / b;
        case Operator.MUL:
            return a * b;
        case Operator.SUB:
            return a - b;
        default:
            throw new Error("wrong operator");
    }
}
compute(Operator.ADD, 1, 3); // 4
// UserE.admin 是一个 枚举成员访问表达式，它返回一个合法的枚举值（数字），所以可以赋值给枚举变量。
// 这是一个数值枚举只能赋值给数字类型变量 或者对应映射的枚举变量 ，ts
// 数值枚举
var UserE;
(function (UserE) {
    UserE[UserE["admin"] = 0] = "admin";
    UserE[UserE["user"] = 1] = "user";
    UserE[UserE["guest"] = 2] = "guest";
})(UserE || (UserE = {}));
let UseUser;
UseUser = UserE.admin;
UseUser = 0;
UseUser = 3;
UseUser = "admin"; //报错
// 字符串枚举
var UserE2;
(function (UserE2) {
    UserE2["admin"] = "admin";
    UserE2["user"] = "user";
    UserE2["guest"] = "guest";
})(UserE2 || (UserE2 = {}));
let UseUser2;
UseUser2 = UserE2.admin;
UseUser2 = "admin"; //报错
var UserE3;
(function (UserE3) {
    UserE3[UserE3["guest"] = 0] = "guest";
    UserE3["admin"] = "admin";
    UserE3["user"] = "user";
})(UserE3 || (UserE3 = {}));
let UseUser3;
UseUser3 = UserE3.admin;
UseUser3 = 0;
// UseUser3 = "admin"
// UseUser3 = 1
var E;
(function (E) {
    E[E["X"] = 0] = "X";
    E[E["Y"] = 1] = "Y";
    E[E["Z"] = 2] = "Z";
})(E || (E = {}));
function f(obj) {
    return obj.X;
}
f(E);
